package  
{
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	import org.flixel.FlxSprite;
	
	/**
	 * ...
	 * @author le-ray_y
	 */
	public class Tower extends FlxSprite 
	{
		// Tower Graphics
		[Embed(source = '../../Assets/witch.png')]
		private static var _towerGraph:Class;
		
		// Timer
		private var _timer:Timer;
		
		// Max Health
		public var _maxHealth:Number;
		
		// Tower Levels
		public var _healthLevel:Number = 0;
		public var _regenLevel:Number = 0;
		public var _spineLevel:Number = 0;
		public var _bowLevel:Number = 0;
		public var _soulLevel:Number = 0;
		
		// Skill Levels
		public var _gasLevel:Number = 0;
		public var _minionLevel:Number = 0;
		public var _oilLevel:Number = 0;
		
		public function Tower(posX:Number = 0, posY:Number = 0, _health:Number = 100) 
		{
			// Initial Position
			this.x = posX;
			this.y = posY;
			
			// Health & Max Health
			this.health = _health;
			this._maxHealth = _health;
			
			// Graphic
			this.loadGraphic(_towerGraph, false, false, 219, 446);
			
			// Regen
			_timer = new Timer(1000, 0);
			_timer.start()
			_timer.addEventListener(TimerEvent.TIMER, timerRegen);
		}
		
		private function timerRegen(e:TimerEvent):void 
		{
			if (health < _maxHealth)
			{
				if (this.health + _maxHealth * (1 * _regenLevel)/100  >= _maxHealth)
				{
					this.health = _maxHealth;
				}
				else
				{
					this.health += _maxHealth * (1 * _regenLevel)/100;
				}
			}
		}
		
		public function damageTower(value:Number):void
		{
			this.health -= value;
		}
		
		override public function update():void
		{
			super.update();
			
			
		}
		
	}

}